﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaceliftCore.MVVM
{
    public abstract class ViewModel : INotifyPropertyChanged
    {
        protected object _model;

        public event PropertyChangedEventHandler PropertyChanged;

        public object Model
        {
            get { return _model; }
            set { _model = value; OnPropertyChange("Model"); }
        }

        protected ViewModel()
        {

        }

        protected ViewModel(object model)
        {
            _model = model;
        }

        protected void OnPropertyChange(string propName)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }

    public abstract class ViewModel<T> : ViewModel
    {
        public new T Model
        {
            get { return (T)_model; }
            set { _model = value; OnPropertyChange("Model"); }
        }

        public ViewModel()
            : base()
        {

        }

        public ViewModel(T model)
            : base(model)
        {

        }
    }
}
